//
//  TstAddressbookCell.swift
//  TstChat
//
//  Created by wanghui on 2018/5/10.
//  Copyright © 2018年 daerwei. All rights reserved.
//

import UIKit
import SnapKit

class ContactCell: UITableViewCell {
    
    static let contactCellId = "contactCell"
    
    //头像
    lazy var headimage: UIImageView = {
        let headImg = UIImageView()
        headImg.layer.cornerRadius = 5
        headImg.layer.masksToBounds = true
        contentView.addSubview(headImg)
        headImg.isUserInteractionEnabled = true
        headImg.backgroundColor = UIColor.clear
        headImg.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageClick)))
        return headImg
    }()
    
    //名称
    lazy var nameLabel: UILabel = {
        let nlabel = UILabel()
//        nlabel.font = UIFont.systemFont(ofSize: 18.0)
        nlabel.textAlignment = .left
        nlabel.numberOfLines = 1
        contentView.addSubview(nlabel)
        return nlabel
    }()
    
    //标签
    lazy var tagbutton: UIButton = {
        let button = UIButton(type: .custom)
        contentView.addSubview(button)
        button.setTitle("创始", for: .normal)
        button.setTitleColor(UIColor.init(red: 81/225, green: 170/225, blue: 56/225, alpha: 1), for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 12.0)
        button.layer.cornerRadius = 12
        button.layer.masksToBounds = true
        button.layer.borderColor = UIColor.init(red: 81/225, green: 170/225, blue: 56/225, alpha: 1).cgColor
        button.layer.borderWidth = 1
        button.isHidden = true
        button.titleEdgeInsets = UIEdgeInsets(top: 2, left: 5, bottom: 2, right: 5)
        
        return button
    }()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .gray
        //添加子view
        self.contentView.addSubview(headimage)
        self.contentView.addSubview(nameLabel)
        self.contentView.addSubview(tagbutton)
        self.backgroundColor = UIColor.systemBackground
        self.separatorInset = UIEdgeInsets(top: 0, left: 60, bottom: 0, right: 0)
        
        headimage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.width.height.equalTo(40)
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(headimage.snp.right).offset(10)
            make.width.lessThanOrEqualTo(UIScreen.main.bounds.size.width - (10+headimage.bounds.size.width+10) - 10)
            make.width.greaterThanOrEqualTo(50)
            make.height.equalTo(18)
        }
        
        tagbutton.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-5)
            make.height.equalTo(25)
            make.width.greaterThanOrEqualTo(40)
            make.left.greaterThanOrEqualTo(nameLabel.snp.right).offset(5)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func imageClick(){
        
    }
}
